package com.bac.rentmap.web.tag;

import java.io.IOException;

import javax.servlet.ServletContext;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.SimpleTagSupport;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

/**
 * Slave server URL tag.
 *
 * @author Andrew Osipenko
 */
public class SlaveServerUrlTag extends SimpleTagSupport {
    @Override
    public void doTag() throws JspException, IOException {
        final ServletContext servletContext = ((PageContext) getJspContext())
                .getServletContext();
        final ApplicationContext context = WebApplicationContextUtils
                .getWebApplicationContext(servletContext);
        String url = (String) context.getBean("slaveServerUrl");

        final JspWriter writer = getJspContext().getOut();
        writer.write(url);
    }
}
